<!-- 逆变器日发电量查询 -->
<template>
	<div class="dashboard-container">
		<div class="form-container">
			<el-form :model="form" label-width="auto" :inline="true">
				<el-form-item :label="$t('message.comprehendReport.pageSubstationChange')">
					<el-select
						v-model="form.substation"
						:placeholder="$t('message.form.pageSelectHolder')"
						style="width: 200px"
						class="custom-select"
						size="default"
					>
						<el-option v-for="item in substationOptions" :key="item.value" :label="item.label" :value="item.value" />
					</el-select>
				</el-form-item>

				<el-form-item :label="$t('message.comprehendReport.pageDeviceChange')">
					<el-select
						v-model="form.device"
						:placeholder="$t('message.form.pageSelectHolder')"
						style="width: 200px"
						class="custom-select"
						size="default"
					>
						<el-option v-for="item in deviceOptions" :key="item.value" :label="item.label" :value="item.value" />
					</el-select>
				</el-form-item>

				<el-form-item :label="$t('message.comprehendReport.pageDateChange')">
					<el-date-picker
						v-model="form.date"
						type="date"
						:placeholder="$t('message.form.pageSelectHolder')"
						class="custom-date-picker"
						size="default"
					/>
				</el-form-item>

				<el-form-item :label="$t('message.comprehendReport.pagePointList')">
					<el-select
						v-model="form.measurementPoint"
						:placeholder="$t('message.form.pageSelectHolder')"
						style="width: 200px"
						class="custom-select"
						size="default"
					>
						<el-option v-for="item in measurementOptions" :key="item.value" :label="item.label" :value="item.value" />
					</el-select>
				</el-form-item>

				<el-form-item>
					<el-button size="default" type="primary" @click="handleSearch">{{ $t('message.form.pageQuery') }}</el-button>
					<el-button size="default" type="warning" @click="handleExport">{{ $t('message.form.pageExport') }}</el-button>
					<el-button size="default" type="success" @click="handlePrint">{{ $t('message.form.pagePrint') }}</el-button>
				</el-form-item>
			</el-form>
		</div>

		<div class="table-container">
			<TableCustom :indexIsShow="true" :total="total" :hasToolbar="false" :tableData="tableData" :tableOption="tableOption" />
		</div>

		<PrintComponent ref="printComponentRef"> </PrintComponent>
	</div>
</template>

<script lang="ts">
import { useI18n } from 'vue-i18n';
import TableCustom from '../../components/table/index.vue';
import PrintComponent from '../../components/print/index.vue';
import { onMounted, defineComponent, reactive, toRefs, computed, ref } from 'vue';

export default defineComponent({
	name: '',

	components: { TableCustom, PrintComponent },

	setup(props, { emit }) {
		const { t } = useI18n();
		const state = reactive({
			total: 0,
			pageSize: 10,
			pageNum: 1, // 表格相关
			tableData: [
				{
					name: '逆变器1',
				},
			],
			form: {
				date: '',
				device: '',
				substation: '',
				measurementPoint: '',
			},
			substationOptions: [
				{ value: '1', label: '子站1' },
				{ value: '2', label: '子站2' },
				{ value: '3', label: '子站3' },
			],
			deviceOptions: [
				{ value: '1', label: '逆变器1' },
				{ value: '2', label: '逆变器2' },
				{ value: '3', label: '逆变器3' },
			],
			measurementOptions: [
				{ value: '1', label: '发电量' },
				{ value: '2', label: '电压' },
				{ value: '3', label: '电流' },
			],
		});

		const handleSearch = () => {
			console.log('Form submitted:', state.form);
		};

		// table表头tableOption国际化
		const tableOption = computed(() => [
			{ prop: 'name', label: t('message.comprehendReport.pageTime') },
			{ prop: 'name', label: t('message.comprehendReport.pageHourPower') },
		]);

		// 打印操作
		const printComponentRef = ref();
		const handlePrint = () => {
			if (printComponentRef.value) {
				printComponentRef.value.printContent();
			}
		};

		// 导出数据
		const handleExport = () => {
			console.log('Exporting data...');

			// var a = document.createElement('a');
			// a.href = BASE_API + '/window/api/pdfinfo/scheduleExportPDF?eventId=' + this.eventId;
			// a.click();
		};

		onMounted(() => {});

		return {
			handleSearch,
			tableOption,
			handlePrint,
			handleExport,
			...toRefs(state),
			printComponentRef,
		};
	},
});
</script>

<style lang="scss" scoped></style>
